<!DOCTYPE html>
<html lang="zh-cn">
<head>
{include file="public/header" /}
</head>
<body>
<div class="panel admin-panel margin-top">
  <div class="body-content">
    <form class="form-x" action="" id="cate-add" name="cate-add">
      <div class="form-group">
        <div class="label">
          <label>上级分类：</label>
        </div>
        <div class="field">
          <select id="options" class="input w50">
            <option value="0">请选择分类</option>
            {volist name="cate" id="vo"}
            <option value="{$vo.id}">{$vo.name_display}</option>
            {/volist}
          </select>
          <div class="tips">不选择上级分类默认为一级分类</div>
        </div>
      </div>
      <div class="form-group">
        <div class="label">
          <label>分类标题：</label>
        </div>
        <div class="field">
          <input type="text" class="input w50" name="name" id="title" />
          <div class="tips"></div>
        </div>
      </div>
      <div class="form-group">
        <div class="label">
          <label>显示：</label>
        </div>
        <div class="field">
          <div class="button-group radio">        
            <input id="isshow" name="sort" type="checkbox" checked="checked">是否显示
           </div>       
        </div>
     </div>
     <div class="form-group">
        <div class="label">
          <label>展现形式：</label>
        </div>
        <div class="field">
          <div class="button-group radio">        
            <input id="isshow" name="sf" type="radio" checked value="1">新闻
            <input id="isshow" name="sf" type="radio" value="2">图片
            <input id="isshow" name="sf" type="radio" value="3">单篇
           </div>       
        </div>
     </div>
      <div class="form-group">
        <div class="label">
          <label></label>
        </div>
        <div class="field">
          <button class="button bg-main icon-feiji" type="submit"> 提交</button>
        </div>
      </div>
    </form>
  </div>
</div>
<script type="text/javascript">

$(function(){
  $('#cate-add').validate({
    rules:{
      name:{
        required:true,
      },
    },
    message:{
      name: {
          required: "标题不能为空",
          minlength: "用户名必需由两个字母组成"
        },
    },
    onkeyup: false,
    focusCleanup: true,
    success: "valid",
    submitHandler:function(form){
      var title= $("#title").val();//标题
      var options=$("#options option:selected").val();//栏目
      var isshow=$("input[type='checkbox']").is(':checked');//是否显示
      var sf=$('input[name="sf"]:checked').val();//展现形式
      if(isshow){
        isshow=1;
      }else{
        isshow=0;
      };
      $.ajax({
        type:"POST",
        url:"{:url('houtai/cate/addajax')}",
        data:{
          'cate':title,
          'pid':options,
          'show':isshow,
          'sf':sf,
        },
        success:function(data){
          var data=eval("("+data+")");
          if (data.status) {
            parent.layer.msg("添加栏目成功！",{icon:1,time:1000,},function(){parent.location.reload();});
          }else{
            parent.layer.msg("添加栏目失败！",{icon:2,time:1000});
          }

        }
      })
    }
  })
})
    
</script>
</body>
</html>